<template>
  <div>
    <el-card class="box-card" style="width: 1180px">
      <div slot="header" class="clearfix">
        <el-form :inline="true" :model="query">
          <el-form-item label="">
            <el-select
              v-model="query.oState"
              placeholder="选择状态"
              style="margin-right: 800px"
              @change="selectChanged"
            >
              <el-option label="进行中" value="1"></el-option>
              <el-option label="未支付" value="2"></el-option>
              <el-option label="已支付" value="3"></el-option>
              <el-option label="全部" value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="oId" label="订单编号" width="100">
        </el-table-column>
        <el-table-column prop="oName" label="订单名称" width="120">
        </el-table-column>
        <el-table-column prop="oTimestart" label="开始时间" width="160">
        </el-table-column>
        <el-table-column prop="oTimeend" label="结束时间" width="160">
        </el-table-column>
        <el-table-column prop="cheweiId" label="车位编号" width="100">
        </el-table-column>
        <el-table-column prop="oBeiyong2" label="本次时长" width="135">
        </el-table-column>
        <el-table-column prop="oConsumption" label="本次消费" width="100">
        </el-table-column>
        <el-table-column prop="oState" label="订单状态" width="110">
          <template slot-scope="scope">
            <p
              v-if="tableData[scope.$index].oState == 1"
              style="color: #ff4949"
            >
              进行中
            </p>
            <p
              v-if="tableData[scope.$index].oState == 2"
              style="color: #3bc053"
            >
              未支付
            </p>
            <p
              v-if="tableData[scope.$index].oState == 3"
              style="color: #3740b7"
            >
              已支付
            </p>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="140" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              v-if="scope.row.oState === 1"
              @click="endOrders(scope.row)"
              round
              >结束</el-button
            >
            <el-button
              type="primary"
              v-if="scope.row.oState === 2"
              @click="pay(scope.row)"
              round
              >支付</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!--分页的实现-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.currentPage"
        :page-sizes="pageInfo.pageSizeS"
        :page-size="pageInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInfo.total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      pageInfo: {
        currentPage: 1,
        pageSizeS: [5, 10, 20, 50],
        pageSize: 5,
        total: 1,
      },
      query: {},
    };
  },

  methods: {
    endOrders(row){
      this.$axios.post("orders/endOrders",row).then(res=>{
        this.$message.success("订单已结束");
        if(typeof(this.query.oState === undefined)){
        
        };
        this.load(2);
      })
    },
    pay(row){
     this.$axios.post("orders/pay",row).then(res=>{
        this.$message.success("支付成功，感谢使用");
        if(typeof(this.query.oState === undefined)){
        
        };
        this.load(2);
      })
    },


    selectChanged(value) {
      this.load(value);
    },
    //当下拉列表改变时
    handleSizeChange(size) {
      this.pageInfo.pageSize = size;
      this.load();
    },
    //当点击页数触发..
    handleCurrentChange(size) {
      this.pageInfo.currentPage = size;

      this.load(this.query.oState);
    },

    load(value) {
      console.log(value);
      let oState = value;
      let u = JSON.parse(sessionStorage.getItem("u"));
      let uId = u.uId;
      this.$axios
        .post("orders/findOrders", {
          uId: uId,
          oState: oState,
          currentPage: this.pageInfo.currentPage,
          pageSize: this.pageInfo.pageSize,
        })
        .then((res) => {

          console.log(res);
          this.tableData = res.data.data.list; //当前页数据
          this.pageInfo.total = res.data.data.total; //得到满足条件的数据条数
        });
    },
  },
  mounted: function () {
    let oState = 1;
    this.load(oState);
  },
};
</script>
<style scoped>
h1,
.box-card {
  margin: auto;
  width: 100%;
}

.el-form-item {
  margin-bottom: 0;
}

[v-cloak] {
  display: none;
}
.uoloadSty .el-upload--picture-card {
  width: 110px;
  height: 110px;
  line-height: 110px;
}
.my-label {
  background: #e1f3d8;
}
</style>